from scavenger import Scavenger
from time import sleep, time

sleep(1.2)

def add(x, y):
    print 'local'
    return x + y

peers = Scavenger.get_peers()

if len(peers) != 0:
    print 'start'

    rdh = Scavenger.perform_service(peers[0], 'daimi.test.add', {'x':17, 'y':1}, timeout=2, store=True)
    rdh.retain = True
    print Scavenger.perform_service(peers[0], 'daimi.test.add', {'x':rdh, 'y':2}, timeout=2)
    print Scavenger.scavenge('daimi.test.add', {'x':rdh, 'y':2},"""
def perform(x, y):
    return x + y
""", add)
    
    result = Scavenger.fetch_data(rdh)

    Scavenger.retain_data(rdh)
    Scavenger.expire_data(rdh)

    print result

    print 'done'
    
Scavenger.shutdown()
